package org.gap.wizards.world.actions;

import java.awt.Point;
import java.util.List;

import org.gap.wizards.world.MapContainer;
import org.gap.wizards.world.MapTransition;
import org.gap.wizards.world.WorldAction;

public class ClimbAction implements WorldAction {

	private final MapContainer world;

	public ClimbAction(MapContainer world) {
		this.world = world;
	}

	@Override
	public void perform() {
		Point character = world.activeMap().getCharacterLocation();
		List<Object> allFromLocation = world.activeMap().getAllFromLocation(character);
		for (Object each : allFromLocation) {
			if (each instanceof MapTransition) {
				MapTransition transition = (MapTransition) each;
				doTransition(transition);
			}
		}
	}

	private void doTransition(MapTransition transition) {
		String mapId = transition.getTransitionToMapId();
		Point toLocation = transition.getTransitionToLocation();
		world.performTransition(mapId, toLocation);
	}
}
